// TOWN SCRIPT
//    Town 7: Farthest

// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documenation. States you write
// yourself should be numbered from 10-100.

// flags:
// 7, 5 / 7, 6 = traps in watcher's tower.
// 7, 9 = Jackie conversation flag.
// 7, 10 = Laura conversation flag.
// 7, 11 = Belinda conversation flag.
// 7, 12 = Thomas conversation flag.
// 7, 13 = know to ask Belinda about tower.

begintownscript;

variables;

short i, choice;

body;

beginstate INIT_STATE;
	set_crime_tolerance(5);

	set_name(6, "Father Ian");
	set_char_dialogue_pic(6, 543, 0);
	set_name(7, "Jackie");
	set_char_dialogue_pic(7, 523, 0);
	set_name(8, "Laura");
	set_char_dialogue_pic(8, 536, 0);
	set_name(9, "Belinda");
	set_char_dialogue_pic(9, 522, 0);
	set_name(10, "Thomas");
	set_char_dialogue_pic(10, 538, 0);

	// reset temple sign flag
	set_flag(7, 0, 0);

	// display entry message
	if (get_flag(2, 20) == 0) {
		if (get_flag(7, 7) == 0) {
			set_flag(7, 7, 1);
			message_dialog("As the party enters Farthest, the people of this remote empire village stop and stare suspiciously, whispering amongst themselves.", "It doesn't appear as if many will help at this moment in time.");
		}
	}
	else {
		// you're empire fiends now...
		if (get_flag(7, 8) == 0) {
			set_flag(7, 8, 1);
			message_dialog("As the party enters the remote empire village of Farthest, the citizens stop and stare.", "When they recognize the party as the ones Mayor Clune sent word of, they go back to doing what they were doing before.");
		}
	}
break;

beginstate EXIT_STATE;
// Always called when the town is left.
break;

beginstate START_STATE;
	if (get_ran(1, 0, 100) < 6) {
		text_bubble_on_char(6, "Bless you.");
	}
	if (get_ran(1, 0, 100) < 6) {
		if (get_flag(2, 20) == 0) {
			text_bubble_on_char(11, "You look suspicious.");
		}
		else {
			text_bubble_on_char(11, "Be careful around here.");
		}
	}
	if (get_ran(1, 0, 100) < 6) {
		if (get_flag(2, 20) == 0) {
			text_bubble_on_char(12, "I'm keeping my eye on you.");
		}
		else {
			text_bubble_on_char(12, "Watch your step.");
		}
	}
break;

beginstate 10;
	if (get_flag(7, 0) == 0) {
		set_flag(7, 0, 1);
		i = 0;
		reset_dialog();
		if (get_flag(7, 1) == 0) {
			set_flag(7, 1, 1);
			add_dialog_str(0, "The temple is very relaxing.", 0);
			add_dialog_str(1, "A large graveyard is out the door to the east.", 0);
			i = 2;
		}
		add_dialog_str(i, "A sign on the wall says:", 0);
		i = i + 1;
		if (char_ok(6))
			add_dialog_str(i, "The priest is *IN*", 10);
		else
			add_dialog_str(i, "The priest is *OUT*", 10);
		add_dialog_choice(0, "OK");
		choice = run_dialog(0);
	}
break;

beginstate 11;
	message_dialog("The shelves are full of hand-carved knick-knacks.", "The collection of dolls, toy carts, statues and other bric-a-brac is engrossing, but useless.");
break;

beginstate 12;
	reset_dialog();
	add_dialog_str(0, "There is a bronze plaque on the pedestal which reads:", 0);
	add_dialog_str(1, "Dedicated to the many who perished in the service of the empire.", 10);
	add_dialog_str(2, "Long live the watchers.", 20);
	add_dialog_str(3, "No where is there any mention of who the watchers were or what service they provided the empire.", 0);
	add_dialog_choice(0, "OK");
	choice = run_dialog(1);
break;

beginstate 13;
	if (has_special_item(6) == 0) {
		set_state_continue(14);
	}
	else {
		set_state_continue(15);
	}
break;

beginstate 14;
	reset_dialog();
	add_dialog_str(0, "The imposing stone building does not seem to have an entrace.", 0);
	add_dialog_str(1, "The building towers over it's neighbor lending to an air of importance.", 0);
	add_dialog_str(2, "What's inside is anybody's guess.", 0);
	add_dialog_choice(0, "OK");
	choice = run_dialog(1);
break;

beginstate 15;
	if (get_terrain(15, 41) != 18) {
		set_terrain(15, 41, 18);
	}
	if (get_flag(7, 2) == 0) {
		set_flag(7, 2, 1);
		reset_dialog();
		add_dialog_str(0, "Carrying the key, the party approachs and searches closely the front of the watchers tower.", 0);
		add_dialog_str(1, "Under a decorative pattern in one of the stones, a keyhole is revealed.", 0);
		add_dialog_str(2, "Using the black key, the door to the tower is unlocked.", 0);
		add_dialog_choice(0, "OK");
		choice = run_dialog(1);
	}
	print_str("The black key unlocks the door into the watcher's tower.");
	play_sound(9);
break;

beginstate 16;
	if (get_flag(7, 3) == 0) {
		set_flag(7, 3, 1);
		// assume party will get map and look at it
		set_flag(231, 0, 1);
		message_dialog("The building has been closed up for a long time.", "The parties footsteps raise up dust on the stairs with each step.");
	}
	// make sure the party can get back out...
	if (get_terrain(15, 41) != 18) {
		set_terrain(15, 41, 18);
	}
break;

beginstate 17;
	message_dialog("The shelves contain maps, figures, journals and ledgers of activities in Avernum.", "It is interesting reading, but is not pertinent to the quest at hand.");
	if (get_flag(7, 4) == 0) {
		if (get_ran(1, 1, 10) < 8) {
			set_flag(7, 4, 1);
			message_dialog("After searching harder, A journal is unearthed containing an entry with a alchemy recipe appropriated from Avernum.", "The recipe allows one to create a brew to make themselves much stronger.");
			give_recipe(15);
			play_sound(8);
		}
	}
break;

beginstate 18;
	message_dialog("The shelves are full of pulp novels written by various empire authors.", "They are engrossing, but useless to the quest at hand.");
break;

beginstate 19;
	if (get_flag(7, 14) == 0) {
		set_flag(7, 14, 1);
		message_dialog("In amongst the novels on the shelves, you find a booklet describing how to kill more effeciently.", "You eagerly read about the technique, feeling yourself become more deadly when finished.");
		play_sound(60);
		alter_stat(1000, 28, 1);
	}
	else {
		set_state_continue(18);
	}
break;

beginstate 20;
	message_dialog("The bookshelves are filled with textbooks and manuals covering all areas of learning.", "You thumb through some, but realize you don't have time to absorb enough of the knowledge to be of any use.");
break;
